import { INPUT_CHANGE, ADD_ITEM, DEL_ITEM } from './actionType'

const defaultStatus = {
	inputValue: 'write something',
	list: ['早上早起，吃早餐', '午间注意休息', '晚上早点睡'],
}

let reducer = (state = defaultStatus, action) => {
	if (action.type === INPUT_CHANGE) {
		let newState = JSON.parse(JSON.stringify(state))
		newState.inputValue = action.value

		return newState
	}
	if (action.type === ADD_ITEM) {
		let newState = JSON.parse(JSON.stringify(state))
		newState.list.push(newState.inputValue)
        newState.inputValue = ''
       
		return newState
	}
	if (action.type === DEL_ITEM) {
		let newState = JSON.parse(JSON.stringify(state))

		newState.list.splice(action.value, 1)
		return newState
	}
	return state
}

export default reducer
